package com.sg.service.base.app.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sg.common.util.CommonFunctionHelper;
import com.sg.dto.base.app.req.QueryEvaFillMemberDetailReq;
import com.sg.entity.OmsEvaluationFillMember;
import com.sg.service.base.app.MOmsEvaluationFillMemberService;
import com.wicket.okrapp.common.dto.FieldInfo;
import com.wicket.okrapp.common.exception.BizException;
import com.wicket.okrapp.dal.mapper.mbg.OmsEvaluationFillMemberMapper;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author ：
 * @version 1.0
 * @since 2022/1/19 15:39
 */
@Service
public class MOmsEvaluationFillMemberServiceImpl
        extends ServiceImpl<OmsEvaluationFillMemberMapper, OmsEvaluationFillMember>
        implements MOmsEvaluationFillMemberService {

    @Autowired
    OmsEvaluationFillMemberMapper omsEvaluationFillMemberMapper;

    /**
     * 3-2-07查询评价填报人员列表[4215]
     * gen by moon at 10/15/2022, 5:45:20 PM
     */
    @Trace(operationName = "3-2-07查询评价填报人员列表")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<OmsEvaluationFillMember> queryEvaFillMemberList(OmsEvaluationFillMember omsEvaluationFillMember) {

        try {
            QueryWrapper<OmsEvaluationFillMember> queryWrapper = new QueryWrapper<>();


            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(omsEvaluationFillMember);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsEvaluationFillMember.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsEvaluationFillMember.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper, likeList, fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsEvaluationFillMember.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);

            return ((List<OmsEvaluationFillMember>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1", e, false);
        }
    }

    /**
     * 3-2-07批量删评价填报人员[4217]
     * gen by moon at 10/15/2022, 5:45:20 PM
     */
    @Trace(operationName = "3-2-07批量删评价填报人员")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean batchDeleteEvaFillMember(List<String> reqDto) {

        if (reqDto == null || reqDto.size() == 0) {
            return false;
        }

        return super.removeByIds(reqDto);
    }

    /**
     * 3-2-07查询评价填报人员详情[4314]
     * gen by moon at 4/24/2023, 12:54:29 AM
     */
    @Trace(operationName = "3-2-07查询评价填报人员详情")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public OmsEvaluationFillMember queryEvaFillMemberDetail(QueryEvaFillMemberDetailReq reqDto) {

        try {
            reqDto.setIsValid("FALSE");
            reqDto.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
            QueryWrapper<OmsEvaluationFillMember> queryWrapper = new QueryWrapper<>();
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, new ArrayList<>());
            queryWrapper.orderByDesc("create_time");
            List<OmsEvaluationFillMember> retList = super.list(queryWrapper);
            if (retList != null && retList.size() > 0) {
                OmsEvaluationFillMember retData = retList.get(0);

                return retData;
            }
            return null;
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1", e, false);
        }
    }

}

